<?php

App::uses('AppHelper', 'View/Helper');

class CertificatesHelper extends AppHelper {
    
    public function passport ($record) {
        $user = $record['data']->certs; ?>
        <table class="">
            <tr>
                <td class="passport">
                    <div class="headPasport">
                        <div>
                            <?php echo $this->_View->Html->image('bosch2.png'); ?>
                        </div>
                        <div>
                            <p><?php echo $record['data']->str->title; ?></p>
                        </div>
                        <div class="iconCategorization">
                            <i class="<?php echo $record['data']->catIcon; ?>" style="color: <?php echo $record['data']->catColor; ?>;"></i>
                        </div>
                    </div>
                    <div class="bodyPassport" >
                        <div>
                            <div class="mla">
                                <?php echo $record['data']->nameLine; ?>
                            </div>
                            <div class="numNom">
                                <?php echo $user[0]->numNom; ?>
                            </div>
                        </div>
                        <div class="nomAsc">
                            <?php echo $user[0]->nameAsc; ?>
                        </div>
                        <div class="tablaCert">
                            <?php if (count($user) > 9) { ?>
                                <table style="width: 50%">
                                    <?php } else { ?>
                                <table style="width: 100%">
                            <?php } ?>
                                <?php
                                    $i = 0;
                                    if (isset($user[$i])) {
                                        for( ; $i < 9; $i++) {
                                            if (isset($user[$i])) { ?>
                                                <tr>
                                                    <td>
                                                        <p class="nameWork"><?php echo $user[$i]->nameWork; ?></p>
                                                    </td>
                                                    <td> 
                                                        <?php if($user[$i]->sucss == '1') { ?>
                                                            <?php echo $this->_View->Html->image('success.png'); ?>
                                                        <?php } elseif ($user[$i]->train == '1') { ?>
                                                            <?php echo $this->_View->Html->image('proces.png'); ?>
                                                        <?php } ?>
                                                    </td>
                                                    <td>
                                                    <?php if($user[$i]->sucss == '1') { ?>
                                                        <p class="fechaCert"><?php echo $user[$i]->life; ?></p>
                                                    <?php } elseif ($user[$i]->train == '1') { ?>
                                                        <p class="fechaFinCert"><?php echo $user[$i]->end; ?></p>
                                                    <?php } ?>
                                                    </td>
                                                </tr>
                                        <?php } else { ?>
                                                <tr>
                                                    <td>&nbsp;</td>
                                                    <td>&nbsp;</td>
                                                    <td>&nbsp;</td>
                                                </tr>
                                        <?php } 
                                        }
                                    }
                                ?>
                            </table>
                            <table>
                                <?php 
                                    if (isset($user[$i])) {
                                        for( ; $i < 18; $i++) { 
                                            if (isset($user[$i])) { ?>
                                                <tr>
                                                    <td>
                                                        <p class="nameWork"><?php echo $user[$i]->nameWork; ?></p>
                                                    </td>
                                                    <td> 
                                                        <?php if($user[$i]->sucss == '1') { ?>
                                                            <?php echo $this->_View->Html->image('success.png'); ?>
                                                        <?php } elseif ($user[$i]->train == '1') { ?>
                                                            <?php echo $this->_View->Html->image('proces.png'); ?>
                                                        <?php } ?>
                                                    </td>
                                                    <td>
                                                    <?php if($user[$i]->sucss == '1') { ?>
                                                        <p class="fechaCert"><?php echo $user[$i]->life; ?></p>
                                                    <?php } elseif ($user[$i]->train == '1') { ?>
                                                        <p class="fechaFinCert"><?php echo $user[$i]->end; ?></p>
                                                    <?php } ?>
                                                    </td>
                                                </tr>
                                        <?php } else { ?>
                                            <tr>
                                                <td>&nbsp;</td>
                                                <td>&nbsp;</td>
                                                <td>&nbsp;</td>
                                            </tr>
                                        <?php } 
                                        }
                                    }
                                ?>
                            </table>
                        </div>
                        <p class="printDate">
                            Fecha de impresi&oacute;n: <?php echo date('Y-m-d', strtotime($record['emission_date'])); ?>
                        </p>
                    </div>
                </td>
                <td class="backPassport">
                        <div class="bodyBPassport">
                            <div>
                                <?php echo $record['data']->str->msg; ?>
                            </div>
                            <div class="qrcode"
                                 data-code="<?php echo Router::url(array('controller' => 'Checker', 'action' => 'index', $record['id']), true); ?>"
                                 data-color="<?php echo $record['data']->catColor; ?>">
                            </div>
                            <div>
                                Elaborado por: <?php echo $record['data']->emi; ?>
                            </div>
                            <div class="bcd kbarcode" data-codeforbar="<?php echo $record['id']; ?>"></div>
                        </div>
                        <div class="footBPassport"><?php echo $record['data']->str->footer; ?></div>
                </td>
            </tr>
        </table>
        <?php
    }
    
    public function certificate ($record) {
        ?>
        <div id="toExport">
            <div id="certificate">
                <?php echo $this->_View->Html->image('MarcoCert.png', array('id' => 'backMarco')); ?>
                <div id="imgHeader">
                    <?php echo $this->_View->Html->image('bosch-logo.png', array('width' => '150px')); ?>
                    <p><?php echo __('ROBERT BOSCH'); ?></p>

                    <p><?php echo __('MÉXICO SISTEMAS AUTOMOTRICES, S.A. DE C.V.'); ?></p>
                </div>
                <div id="msgCert">
                    <p><?php echo __('Otorga el presente'); ?></p>
                    <p><?php echo __('Certificado'); ?></p>
                </div>
                <div id="nameAsc">
                    <p><?php echo __('A');?>:</p>
                    <p><?php echo $record['data']->name; ?></p>
                </div>
                <div id="nameWork">
                    <p><?php echo __('Por haber concluido exitosamente la certificación en la operación: '); ?></p>
                    <p><?php echo $record['data']->workstation; ?></p>
                </div>
                <div id="workImage">
                    <?php echo $this->_View->Html->image($record['data']->img); ?>
                </div>
                <div id="signImages">
                    <div id="gMoe" >
                        <div><?php echo $this->_View->Html->image($record['data']->moe_sign); ?></div>
                        <p><?php echo $record['data']->moe_name; ?></p>
                        <p><?php echo $record['data']->moe_job; ?></p>
                    </div>
                    <div id="gRH" >
                        <div><?php echo $this->_View->Html->image($record['data']->rh_sign); ?></div>
                        <p><?php echo $record['data']->rh_name; ?></p>
                        <p><?php echo $record['data']->rh_job; ?></p>
                    </div>
                    <div id="gS" >
                        <div><?php echo $this->_View->Html->image($record['data']->ts_sign); ?></div>
                        <p><?php echo $record['data']->ts_name; ?></p>
                        <p><?php echo $record['data']->ts_job; ?></p>
                    </div>
                </div>
                <div id="dateExp">
                    <p data-date="<?php echo $record['date']; ?>"><?php echo __('San Luis Potosí, S. L. P., a '); ?></p>
                </div>
            </div>
            <div id="backCertificate" class="page-break">
                <div class="qrcode"
                     data-code="<?php echo Router::url(array('controller' => 'Checker', 'action' => 'index', $record['id']), true); ?>"
                     data-color="#000000"></div>
                <div class="bcd kbarcode" data-codeforbar="<?php echo $record['id']; ?>"></div>
            </div>
        </div>
        <?php
    }

    public function diploma ($record) {
        ?>
        <div id="toExport">
            <div id="diploma">
                <?php echo $this->_View->Html->image('MarcoCert.png', array('id' => 'backMarco')); ?>
                <div id="imgHeader">
                    <?php echo $this->_View->Html->image('bosch-logo.png', array('width' => '150px')); ?>
                    <p><?php echo __('ROBERT BOSCH'); ?></p>
                    <p><?php echo __('MEXICO SISTEMAS AUTOMOTRICES, S.A. DE C.V.'); ?></p>
                </div>
                <div id="msgCert">
                    <p><?php echo __('Otorga el presente'); ?></p>
                    <p><?php echo __('Diploma'); ?></p>
                </div>
                <div id="nameAsc">
                    <p><?php echo __('A');?>:</p>
                    <p><?php echo $record['data']->name; ?></p>
                </div>
                <div id="nameWork">
                    <p><?php echo __('Por haber concluido exitosamente el curso: '); ?></p>
                    <p><?php echo $record['data']->training; ?></p>
                    <p><?php echo __('y aplicar dichos conocimientos diariamente'); ?></p>
                </div>
                <div id="signImages">
                    <div id="gMoe" >
                        <div><?php echo $this->_View->Html->image($record['data']->moe_sign); ?></div>
                        <p><?php echo $record['data']->moe_name; ?></p>
                        <p><?php echo $record['data']->moe_job; ?></p>
                    </div>
                    <div id="gRH" >
                        <div><?php echo $this->_View->Html->image($record['data']->rh_sign); ?></div>
                        <p><?php echo $record['data']->rh_name; ?></p>
                        <p><?php echo $record['data']->rh_job; ?></p>
                    </div>
                    <div id="gS" >
                        <div><?php echo $this->_View->Html->image($record['data']->ts_sign); ?></div>
                        <p><?php echo $record['data']->ts_name; ?></p>
                        <p><?php echo $record['data']->ts_job; ?></p>
                    </div>
                </div>
                <div id="dateExp">
                    <p data-date="<?php echo $record['date'];?>"><?php echo __('San Luis Potosí, S. L. P. al '); ?></p>
                </div>
            </div>
            <div id="backDiploma" class="page-break">
                <div class="qrcode"
                     data-code="<?php echo Router::url(array('controller' => 'Checker', 'action' => 'index', $record['id']), true); ?>"
                     data-color="#000000"></div>
                <div class="bcd kbarcode" data-codeforbar="<?php echo $record['id']; ?>"></div>
            </div>
        </div>
    <?php
    }

    public function kardex($info) {
        ?>
            <div id="kardex">
                <div class="header-bosch visible-print">
                    <?php echo $this->_View->Html->image('bosch-logo.png', array('width' => '100px')); ?>
                </div>
                <div class="header visible-print">
                    <p><?php echo __('Kardex'); ?></p>
                </div>
                <div class="kardex-content">
                    <div class="personalInfo">
                        <div class="subtitle">
                            <p class="myname"><?php echo $info['user']['full_name']; ?></p>
                            <p class="myname"><?php echo $info['user']['nomina']; ?></p>
                        </div>
                        <div class="imgUsr">
                            <?php echo $this->_View->Html->image('workers/' . $info['user']['nomina'] . '.jpg', array('width' => '100px')); ?>
                        </div>
                    </div>
                    <div class="tableCert">
                        <?php
                            $tam = count($info['certifications']);
                            if ($tam != 0) { ?>
                                <table class="table table-bordered">
                                    <thead>
                                        <tr>
                                            <th colspan="7" class="subtitle"><?php echo __('Mis certificaciones'); ?></th>
                                        </tr>
                                        <tr>
                                            <th colspan="2"><?php echo __('Operación'); ?></th>
                                            <th><?php echo __('Evaluación en piso'); ?></th>
                                            <th><?php echo __('Validación en piso'); ?></th>
                                            <th><?php echo __('Examen de certificación'); ?></th>
                                            <th><?php echo __('Fecha de certificación'); ?></th>
                                            <th><?php echo __('Vigencia'); ?></th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                            for($i=0; $i<$tam; $i++) { ?>
                                                <tr>
                                                    <td>
                                                        <?php if($info['certifications'][$i]['success'] == '1' && $info['certifications'][$i]['training'] == '0') { ?>
                                                            <i class="fa fa-check"></i>
                                                        <?php } elseif ($info['certifications'][$i]['success'] == '0' && $info['certifications'][$i]['training'] == '1') { ?>
                                                            <i class="fa fa-flag"></i>
                                                        <?php } elseif ($info['certifications'][$i]['success'] == '0' && $info['certifications'][$i]['training'] == '0') { ?>
                                                            <i class="fa fa-times"></i>
                                                        <?php }?>
                                                    </td>
                                                    <?php
                                                        $s = array();
                                                        $s[] = $info['certifications'][$i]['moe'];
                                                        $s[] = $info['certifications'][$i]['area'];
                                                        $s[] = $info['certifications'][$i]['line'];
                                                        $s[] = '<strong>' . $info['certifications'][$i]['work'] . '</strong>';
                                                        $s = array_unique($s);
                                                        $s = implode('-', $s);
                                                    ?>
                                                    <td><?php echo $s; ?></td>
                                                    <td class="<?php echo $info['certifications'][$i]['EvPisoAp'] == '1' ? 'aprobated' : ''; ?>">
                                                        <strong><?php echo number_format(floatval($info['certifications'][$i]['EvPiso'])); ?></strong>
                                                    </td>
                                                    <td class="<?php echo $info['certifications'][$i]['CertPisoAp'] == '1' ? 'aprobated' : ''; ?>">
                                                        <strong><?php echo number_format(floatval($info['certifications'][$i]['CertPiso'])); ?></strong>
                                                    </td>
                                                    <td class="<?php echo $info['certifications'][$i]['examCertAp'] == '1' ? 'aprobated' : ''; ?>">
                                                        <strong><?php echo number_format(floatval($info['certifications'][$i]['examCert'])); ?></strong>
                                                    </td>
                                                    <td class="dateToTransform" data-date="<?php echo $info['certifications'][$i]['end']; ?>"></td>
                                                    <td class="dateToTransform" data-date="<?php echo $info['certifications'][$i]['life']; ?>"></td>
                                                </tr>
                                        <?php } ?>
                                    </tbody>
                                </table>
                            <?php } else { ?>
                                <div class="alert alert-info">
                                    No tiene certificaciones
                                </div>
                            <?php } ?>
                    </div>
                    <div class="tableCourses">
                        <?php
                            $tamC = count($info['trainings']['calificated']);
                            $tamT = count($info['trainings']['training']);
                            if ( $tamC + $tamT > 0) { ?>
                                <table class="table table-bordered">
                                    <thead>
                                        <tr>
                                            <th colspan="5" class="subtitle"><?php echo __('Mis cursos'); ?></th>
                                        </tr>
                                        <tr>
                                            <th colspan="2"><?php echo __('Curso'); ?></th>
                                            <th><?php echo __('Contenido'); ?></th>
                                            <th><?php echo __('Calificación'); ?></th>
                                            <th><?php echo __('Fecha'); ?></th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                            for($i=0; $i<$tamC; $i++) { ?>
                                                <tr>
                                                    <td>
                                                        <?php if($info['trainings']['calificated'][$i]['aprobated'] == '1') { ?>
                                                            <i class="fa fa-check"></i>
                                                        <?php } else { ?>
                                                            <i class="fa fa-times"></i>
                                                        <?php } ?>
                                                    </td>
                                                    <?php
                                                        $s = explode('-', $info['trainings']['calificated'][$i]['course']);
                                                        $j = count($s)-1;
                                                        $s[$j] = '<strong>' . $s[$j] . '</strong>';
                                                    ?>
                                                    <td>
                                                        <?php echo implode('-', $s); ?>
                                                    </td>
                                                    <td class="courses-content">
                                                        <ul>
                                                            <?php
                                                                $tamIntern = count($info['trainings']['calificated'][$i]['themes']);
                                                                for($j=0; $j<$tamIntern; $j++) {
                                                                    if ($info['trainings']['calificated'][$i]['themes'][$j]['theme'] != '') { ?>
                                                                    <li><?php echo $info['trainings']['calificated'][$i]['themes'][$j]['theme']; ?></li>
                                                                <?php }
                                                                } ?>
                                                        </ul>
                                                    </td>
                                                    <td class="<?php echo $info['trainings']['calificated'][$i]['aprobated'] == '1' ? 'aprobated' : ''; ?>">
                                                        <strong><?php echo number_format(floatval($info['trainings']['calificated'][$i]['calif'])); ?></strong>
                                                    </td>
                                                    <td class="dateToTransform" data-date="<?php echo $info['trainings']['calificated'][$i]['date']; ?>"></td>
                                                </tr>
                                            <?php }
                                                for($i=0; $i<$tamT; $i++) { ?>
                                                <tr>
                                                    <td><i class="fa fa-flag"></i></td>
                                                    <td><?php echo $info['trainings']['training'][$i]['course']; ?></td>
                                                    <?php
                                                        $tamIntern = count($info['trainings']['training'][$i]['themes']);
                                                        $s = array();
                                                        for($j=0; $j<$tamIntern; $j++) {
                                                            $s[] = $info['trainings']['training'][$i]['themes'][$j]['theme'];
                                                        }
                                                        $s = implode(', ', $s);
                                                    ?>
                                                    <td><?php echo $s; ?></td>
                                                    <td></td>
                                                    <td class="dateToTransform" data-date="<?php echo $info['trainings']['training'][$i]['date']; ?>"></td>
                                                </tr>
                                            <?php } ?>
                                    </tbody>
                                </table>
                            <?php } else { ?>
                                <div class="alert alert-info">
                                    No tiene cursos
                                </div>
                            <?php } ?>
                    </div>
                    <div class="tableSummary">
                        <?php if ($tam + $tamC + $tamT) { ?>
                            <table class="table table-bordered">
                                <thead>
                                    <tr>
                                        <th colspan="4" class="subtitle"><?php echo __('Mi resumen'); ?></th>
                                    </tr>
                                    <tr>
                                        <th><?php echo __('Área'); ?></th>
                                        <th><?php echo __('Certificaciones'); ?></th>
                                        <th><?php echo __('Certificaciones en entrenamiento'); ?></th>
                                        <th><?php echo __('Nivel'); ?></th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php
                                    $tam = count($info['summary']);
                                    for($i=0; $i<$tam; $i++) { ?>
                                        <tr>
                                            <?php
                                                $s = array();
                                                $s[] = $info['summary'][$i]['moe'];
                                                $s[] = $info['summary'][$i]['area'];
                                                $s[] = $info['summary'][$i]['line'];
                                                $s = array_unique($s);
                                                $s = implode('-', $s);
                                            ?>
                                            <td><?php echo $s; ?></td>
                                            <td><?php echo $info['summary'][$i]['certs']; ?></td>
                                            <td><?php echo $info['summary'][$i]['trains']; ?></td>
                                            <td class="iconCert"><i class="<?php echo $info['summary'][$i]['level']; ?>" style="color: <?php echo $info['summary'][$i]['color']; ?> !important; @media print { color: <?php echo $info['summary'][$i]['color']; ?> !important; }"></i></td>
                                        </tr>
                                    <?php } ?>
                                </tbody>
                            </table>
                        <?php } ?>
                    </div>
                </div>
                <div class="visible-print">
                    <p>
                        <?php
                            $d = new DateTime();
                            echo __('Esta es una representación impresa del kárdex de carácter informativo. La información actualizada la puedes consultar en ');
                            echo Router::url('/', true);
                            echo __('. Impreso el ');
                            echo '<span class="print-date" data-date="' . $d->format('Y-m-d') . '"></span>';
                            echo __(' desde ');
                            echo $_SERVER['REMOTE_ADDR'];
                            echo __(' por el usuario ');
                            echo $info['user']['full_name'];
                        ?>
                    </p>
                </div>
            </div>
        <?php
    }
}